<?php
// +----------------------------------------------------------------------
// | HisiPHP框架[基于ThinkPHP5.1开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2016-2021 http://www.HisiPHP.com
// +----------------------------------------------------------------------
// | HisiPHP承诺基础框架永久免费开源，您可用于学习和商用，但必须保留软件版权信息。
// +----------------------------------------------------------------------
// | Author: 橘子俊 <364666827@qq.com>，开发者QQ群：50304283
// +----------------------------------------------------------------------

namespace app\system\admin;  

use app\system\model\SystemDaili as DailiModel;
use think\Db;
 
/**
 * 代理管理控制器
 * @package app\system\admin
 */
class Chongzhi extends Admin
{ 
    /**
     * 购买记录
     */
    public function gmjl(){
        $cg_list = Db::name("cgjl")->where("pay_status = 0")->select();
        foreach ($cg_list as $key => $val){
            $cg_list[$key]['daili'] = $daili_info = Db::name("daili")->where("id = '{$val['dl_id']}'")->find();
            $cg_list[$key]['levelname'] = Db::name("dldj")->where("id = '{$daili_info['lddj_id']}'")->value('levelname');
        }
        $this->assign("cg_list",$cg_list);
        return $this->fetch();
    }
    
    /**
     * 购买记录-已审核
     */
    public function gmjlYsh(){
        $cg_list = Db::name("cgjl")->where("pay_status = 1")->select();
        foreach ($cg_list as $key => $val){
            $cg_list[$key]['daili'] = $daili_info = Db::name("daili")->where("id = '{$val['dl_id']}'")->find();
            $cg_list[$key]['levelname'] = Db::name("dldj")->where("id = '{$daili_info['lddj_id']}'")->value('levelname');
        }
        $this->assign("cg_list",$cg_list);
        return $this->fetch();
    }
    
    /**
     * 采购审核
     */
    public function cgsh(){
        if($this->request->isPost()){
            $data = $this->request->post();
            $dl_model = new DailiModel();
            if (!$dl_model->shenheCgjl($data)) {
                return $this->error('审核失败');
            }
            return $this->success('审核成功',url('chongzhi/gmjl')); 
        }else{
            $id = $this->request->param('id');
            $cg_info = Db::name("cgjl")->where("id = '{$id}'")->find();
            $cg_info['dlname'] = Db::name("daili")->where("id = '{$cg_info['dl_id']}'")->value("dlname");
            $this->assign("cg_info",$cg_info);
            return $this->fetch();
        }
    }
}
